const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const glob = require("glob");

const entries = {};

glob.sync("./views/**/*.js").forEach(item => {
    entries[item] = path.resolve(__dirname, item);
});

console.log(entries);
// return;


module.exports = {
    mode: "development", // production
    entry: entries, //指定入口文件，程序从这里开始编译,__dirname当前所在目录, ../表示上一级目录, ./同级目录
    output: {
        path: path.resolve(__dirname, 'public'), // 输出的路径
        filename: '[name]'  // 打包后文件
    },
    //progress: true,
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['es2015', 'react', 'stage-0'], //'es2015', 
                        plugins: [
                            ["import", {
                                "libraryName": "antd",
                                "libraryDirectory": "es",
                                "style": "css" // `style: true` 会加载 less 文件
                            }],
                            //"@babel/plugin-transform-runtime"
                        ]
                    }
                },
                exclude: /node_modules/
            }, {
                test: /\.css$/,
                use: [{
                    loader: 'style-loader'
                }, {
                    loader: 'css-loader'
                }]
            }
        ]
    },
    
    devServer: {
        //contentBase: path.join(__dirname, "dist"),
        contentBase: path.join(__dirname, "public"),
        port: 7000,
        //publicPath:'/'
        //overlay: true,
        host: '0.0.0.0',
        progress: true,
        disableHostCheck: true,
        stats: "errors-only",
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
            "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
        }
    }

    // ,plugins: [
    //     new HtmlWebpackPlugin({
    //         template: path.resolve(__dirname, 'src/index.template.html'),
    //         inject: true
    //     })
    // ]
}